/*
 * PlaylistInsertAction.java
 *
 * Created on April 8, 2006, 1:28 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package com.bff.slimserver.musicjukebox.lib.actions;

import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import com.bff.slimserver.musicjukebox.ui.SplashScreen;
import com.bff.slimserver.musicjukebox.ui.components.podcast.PodcastInfoDialog;
import com.bff.bjj.utils.Resources;
import java.awt.event.ActionEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import org.bff.slimserver.exception.SlimConnectionException;
import org.bff.slimserver.exception.SlimNetworkException;
import org.bff.slimserver.musicobjects.SlimPodcastAudioDetails;
import org.bff.slimserver.musicobjects.SlimPodcastItem;

/**
 *
 * @author Bill
 */
public class ViewPodcastAction extends AbstractAction {

    private SlimPodcastItem item;
    private JFrame parent;
    private SplashScreen sp;

    /** Creates a new instance of PlaylistInsertAction */
    public ViewPodcastAction(JFrame parent, SlimPodcastItem item) {
        this.item = item;
        this.parent = parent;
        putValue(Action.NAME, Resources.getMessage(Resources.LABEL_KEY.ACTION_VIEW_PODCAST_NAME));
        putValue(Action.SHORT_DESCRIPTION, Resources.getMessage(Resources.LABEL_KEY.ACTION_VIEW_PODCAST_SHORT_DESC));
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        sp = new SplashScreen(parent, true);
        sp.setIndeterminate(true);
        sp.setTitleLabel(Resources.getMessage(Resources.LABEL_KEY.PODCAST_LOADING_TITLE));
        sp.setMainTextArea(Resources.getMessage(Resources.LABEL_KEY.PODCAST_LOADING_TEXT, new Object[]{item}));
        sp.setProgressBarLabel(Resources.getMessage(Resources.LABEL_KEY.PODCAST_LOADING_PROGRESS_BAR));
        sp.pack();

        new Thread(new Runnable() {

            @Override
            public void run() {
                SlimPodcastAudioDetails podcastDetails = null;
                try {
                    podcastDetails = JukeboxProperties.getInstance().getPodcaster().getPodcastAudioDetails(item);
                } catch (SlimConnectionException ex) {
                    Logger.getLogger(ViewPodcastAction.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SlimNetworkException ex) {
                    Logger.getLogger(ViewPodcastAction.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    sp.setVisible(false);
                }

                new PodcastInfoDialog(parent, enabled, podcastDetails).setVisible(true);
            }
        }).start();

    }
}
